/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.atm.domain;

/**
 *
 * @author Rahul
 */
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.atm.util.Utils;

@Entity
@Table(name = "Account")
@NamedQueries({
    @NamedQuery(name = "Account.findAll", query = "SELECT c FROM Account c"),
    @NamedQuery(name = "Account.findByAccountId", query = "SELECT a FROM Account a WHERE a.accountId = :accountId"),
        @NamedQuery(name = "Account.findByAccountNumber", query = "SELECT a FROM Account a WHERE a.number = :number")
})
public class Account implements Serializable {

    public static final String ACTIVATE = "Activated";
    public static final String DEACTIVATE = "Deactivated";
    public static final String CHEQUING = "Chequing";
    public static final String SAVINGS = "Savings";
    private static final long serialVersionUID = 1L;
    @Id @GeneratedValue(strategy = GenerationType.TABLE)
    @Basic(optional = false)
    @Column(name = "ACCOUNT_ID")
    private Integer accountId;
    @Column(name = "ACCOUNT_NUMBER")
    private Integer number;
    @Column(name = "TYPE")
    private String type;
    @Column(name = "amount")
    private double amount;
    @Column(name = "STATE", nullable = false)
    private String state;
    @ManyToOne
    private Client client;

    public Account() {
    }

    public Account(Integer accountId) {
        this.accountId = accountId;
    }

    public static Account createAccount(String type) {
        Account account = new Account();
        account.setNumber(Utils.generateRandomInteger(1000000, 9999999));
        account.setType(type);
        account.setState("");
        return account;
    }

    @Override
    public String toString() {
        return "Account{" + "number=" + number + ", type=" + type + '}';
    }

    public Integer getAccountId() {
        return accountId;
    }

    public void setAccountId(Integer accountId) {
        this.accountId = accountId;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public void getActivate() {
        this.state = ACTIVATE;
    }

    public void setActivate() {
        this.state = ACTIVATE;
    }

    public void getDeactivate() {
        this.state = DEACTIVATE;
    }

    public void setDeactivate() {
        this.state = DEACTIVATE;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }
}
